<?php  
defined('APPLICATION_URL')||define('APPLICATION_URL', '/ITjap(tung)/ITjap_finalversion');
session_start();
$userId=$_SESSION['userId'];
if(!isset($userId)) header('Location:'.APPLICATION_URL.'/index.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- head - Finished -->
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<link rel="stylesheet" href="../../css/layout.css" type="text/css" media="screen" />
	<link rel="stylesheet" href="../../css/home.css" type="text/css" media="screen" />
	<link rel="stylesheet" href="../../css/room_managerment.css" type="text/css" media="screen" />
	<script src="../../js/jquery-1.7.2.min.js"language="javascript"></script>
	<title>会議室予約システム</title>
</head>
<!-- /head - Finished -->
		<script type="text/javascript">
		$(document).ready(function(){
			$("#add").click(function() {	
				  $('#edit_').hide();
				  $('#delete_').hide();		
				  $('#add_').show("fast");
				  $("#add_form").submit(function(){
					  var roomName=$("#roomName").val();
					  var roomCategory=$("#roomCategory").val();
					  var roomSeatCount=$("#roomSeatCount").val();
					  var roomCost=$("#roomCost").val();
					  if(checkForm()!=false)
					  {
					  $.ajax({
						  url: "/ITjap(tung)/ITjap_finalversion/controller/addRoomController.php",
						  type: "POST",
						  data:"roomName="+roomName+"&roomCategory="+roomCategory+"&roomSeatCount="+roomSeatCount+"&roomCost="+roomCost,
						  success : function(data){
							switch (data) {
							case '-1':
								alert("wrong room name");
								break;
							case '0':
								alert("error while add room");
								break;	
							case '1':
								alert("add successful");
								break;
							}
						  //alert(data);
						 },
						 error : function(){
							 alert("error");
						 }
						});
					  }		
					return false;
				});					
			 });
			$("#edit").click(function() {
				  $('#add_').hide();
				  $('#delete_').hide();	
				  $('#edit_').show("fast");
				  $("#edit_form").submit(function(){
					  //var index=$("#edit_form").name.selectedIndex;
					  var name=document.getElementById("name").value;
					  var roomName=$("#roomName2").val();
					  var roomSeatCount=$("#roomSeatCount2").val();
					  var roomCost=$("#roomCost2").val();
					  if(checkForm1()!=false)
					  {
					  //alert(roomName);
					  $.ajax({
						  url: "/ITjap(tung)/ITjap_finalversion/controller/changeRoomInfoController.php",
						  type: "POST",
						  data:"name="+name+"&roomName="+roomName+"&roomSeatCount="+roomSeatCount+"&roomCost="+roomCost,
						  success : function(data){
							switch (data) {
							case '-1':
								alert("invalid input");
								break;	
							case '0':
								alert('error while update room info');
								break;		
							case '1':
								alert("update successful");
								break;
							default:
								alert(data);	
							}
						 //alert(data);
						 },
						 error : function(){
							 alert("error");
						 }
						});
					  }		
					return false;
				});
				});
			$("#delete").click(function() {
				  $('#add_').hide();
				  $('#edit_').hide();	
				  $('#delete_').show("fast");
				});
			function checkForm()
			{
				var x=document.forms["addroom"]["roomName"].value;
				var t=document.forms["addroom"]["roomCategory"].value;
				var y=document.forms["addroom"]["roomSeatCount"].value;
				var z=document.forms["addroom"]["roomCost"].value;
				if (x==null || x=="" ||y==null || y=="" || z==null || z=="" || t==null || t=="")
				  {
					  alert("Blank must be filled out");
					  return false;
				  }
			}
			function checkForm1()
			{
				var x=document.forms["editroom"]["roomName"].value;
				var y=document.forms["editroom"]["roomSeatCount"].value;
				var z=document.forms["editroom"]["roomCost"].value;
				if (x==null || x=="" ||y==null || y=="" || z==null || z=="")
				  {
					  alert("Blank must be filled out");
					  return false;
				  }
			}
		}); 
		</script>
<body>
<!-- header area -->
	<div id="header_area">
	  <div id="header">
	    <div id="header_link_area">
	      <a name="pagetop"></a>
	      <div id="header_appeal">会議室予約システム</div>
	      <div id="header_link">
	       <ul>
	          <li class="header_b_1"><a href="admin.php" class="header_b_1"><img src="../../images/header/header_b_1.gif" alt="ホーム" width="56" height="21" /></a></li>
	          <li class="logout"><a href="../../controller/logout.php" class="header_b_2"><img src="../../images/header/header_b_5.gif" alt="logout" width="71" height="21" /></a></li>
	          <li class="setting"><a href="../../change_pass.php" class="header_b_3"><img src="../../images/header/header_b_3.gif" alt="setting"" width="155" height="21" /></a></li>
	          <li class="header_b_4"><a href="../../index.php" class="header_b_4"><img src="../../images/header/header_b_4.gif" alt="お問い合せ" width="82" height="21" /></a></li>
	        </ul>
	      </div>
	    </div>
	    <div id="header_title">
	       <img id="SiteHeader1_imgTitle" src="../../images/header/header_title_1.gif" alt="貸会議室予約" style="height:90px;width:960px;border-width:0px;" /> 
	    </div>
	  </div>
	</div>
<!-- header area-->
	
<!-- pan_area -->
	      <div id="pan_area">
	        <div id="pan">
	          
	        </div>
	      </div>
<!-- pan_area -->
	  
<!-- main_area -->
	<div id="main_top_area">&nbsp;</div>
	    
	<!-- main_middle_area -->   
	<div id="main_middle_area">
	
	    <!-- main area-->
		<div id="main_area">
		
			<!-- main -->
			<div id="main">
				   <!-- navi -->
				      <div id="navi">
				        <ul>
				          <li class="kanrisha_shitsu"><a href="room_manager.php" class="navi_b_1"><img src="../../images/navi/kanrisha_shitsu.gif" alt="kanrisha_shitsu" width="145" height="39" /></a></li>
				          <li class="kanrisha_user"><a href="<?php echo APPLICATION_URL?>/controller/userManagerController.php" class="navi_b_2"><img src="../../images/navi/kanrisha_user.gif" alt="kanrisha_user" width="145" height="39" /></a></li>
				          <li class="kanrisha_penalty"><a href="unauthorized_detect.php" class="navi_b_3"><img src="../../images/navi/kanrisha_penalty.gif" alt="kanrisha_penalty" width="145" height="39" /></a></li>
				        </ul>
				      </div>
				   <!-- /navi -->
				   
				   <!-- contents -->
				       <div id="content">
				       		  <h1><img src="../../images/h1_faq.gif" alt="よくあるご質問" /></h1>
				       		  <h1 style="color: Blue">会議室管理</h1>
				       		  <div id="buttons">
				       		  		<button id="add">会議室追加</button>
				       		  		<button id="edit">会議室変更</button>
				       		  		<button id="delete">会議室削除</button>
				    
				       		  </div>
		<!--FORM ADD ROOM-->	       		  
				       		  <div id = "add_" style="display: none">
				       		  	<div id="Add_room">
				       		  	  <form id="add_form" method="post"  name="addroom">	  			          		
								            <div id="room_name">
									              <label for="room_name">会議室の名前</label>
									              <input name="roomName" type="text" id="roomName" class="width_20" />
								            </div>
								            <div id="category">
									              <label for="category">種類</label>
									              <input name="roomCategory" type="text" id="roomCategory" class="width_20" />
								            </div>
								            <!-- password -->
								            <div id="seat_count">
									              <label for="seat_count">席数</label>
									              <input name="roomSeatCount" type="text" id="roomSeatCount" class="width_20" />
								            </div>
								            <div id="price">
									              <label for="price">課金</label>
									              <input name="roomCost" type="text" id="roomCost" class="width_20" />
								            </div>  
								            <!-- button -->		
								              	<input type="submit" name="add" value="追加" id="submit" />
								              	<input type="reset" name="add" value="レセット" id="reset" />								            		            
						          </form>
						        </div>  
				       		  </div>
				       		  <div id = "edit_" style="display: none">
		<!--FORM EDIT ROOM-->
				       		  	
					       	   <div id="Edit_Room" style="margin-top: 30px">
					       		  	<form id="edit_form" method="post" name="editroom" action="./updateRoomInfo.php">	
					       		  		<label style="font-size: 1.5em">会議室を選んでください</label>
								       	  	<?php
								       	  		include '../../models/Model.php';
						                  	 	$model=new Model();
						                  	 	$room_list=$model->searchAllRoom();
							                  	//$room_list = array("会議室A","会議室B", "会議室C", "会議室D", "会議ブースH","会議ブースI", "会議ブースJ");
							                  	 print"<select style=\"margin-left: 20px\" name=\"roomName\" id=\"name\">";
							                  	  foreach ($room_list as $room){ 		
							                  	  	if($room->getRoomCategory()==1)
							                  	  			$roomName='会議室'.$room->getRoomName();
							                  	  	else
							                  	  			$roomName='会議ブース'.$room->getRoomName();									                  	  						                  
												  	print"<option value=\"$roomName\" name=\"roomName\">$roomName</option>";																			  
							                  	 }
							                  	 print"</select>";
										  	?>
											     <br><input type="submit" name="add" value="変更" id="submit" /></br> 	
									              				 
								      </form>
								</div>
								
				       		  </div>
		<!--FORM DELETE ROOM-->		       		  
				       		  <div id = "delete_" style="display: none">
				       		  	<form action="../../controller/deleteRoomController.php" method="post">
					       		  	<div id="Delete_Room" style="margin-top: 30px">
					       		  		<label style="font-size: 2em">会議室を選んでください </label>
								       	  	<?php
							                  	//include '../../models/Model.php';
						                  	 	$model=new Model();
						                  	 	$room_list=$model->searchAllRoom();
							                  	//$room_list = array("会議室A","会議室B", "会議室C", "会議室D", "会議ブースH","会議ブースI", "会議ブースJ");
							                  	 print"<select style=\"margin-left: 20px\" name=\"name\" id=\"name\">";
							                  	  foreach ($room_list as $room){ 			
							                  	  	if($room->getRoomCategory()==1)
							                  	  			$roomName='会議室'.$room->getRoomName();
							                  	  	else
							                  	  			$roomName='会議ブース'.$room->getRoomName();		                  
												  	print"<option value=\"$roomName\">$roomName</option>";																			  
							                  	 }
							                  	 print"</select>";
										  	?>										  
									</div>
									<!-- button -->		     
						              	<input style="margin-top: 20px" type="submit" name="Delete" value="削除" id="submit" />						            
								</form>
				       		  </div>
				       		  
				       		
				       		<p>&nbsp;</p>        
                              <p>&nbsp;</p>        
                              <p>&nbsp;</p>      
                              <p>&nbsp;</p>        
                              <p>&nbsp;</p>        
                              <p>&nbsp;</p>        
                              <p>&nbsp;</p>        
                              <p>&nbsp;</p>        
                              <p>&nbsp;</p>        
                              <p>&nbsp;</p>  
				       	</div> 
				    <!-- /contents -->
				    
			</div>
	  		<!-- /main -->
	  		
		      <div id="pr"><p>&nbsp;</p></div>
			</div>
	    </div>
	     <!-- /main_middle_area -->
	<div id="main_bottom_area">&nbsp;</div>
<!-- main_area -->
      
<!-- FOOTER -->
	<div id="footer_area">
	  <div id="footer">
	    <ul>
	      <li class="left"><a href="../../index.php">ホーム</a></li>
	      <li><a href="../../view/user/login.php">ログアウト</a></li>
	      <li><a href="../../view/user/register.php">個人情報変更</a></li>
	      <li><a href="../../index.php">Q&A</a></li>
	    </ul>
	    <p>Copyright&nbsp;&copy;&nbsp;Team 08</p>
	  </div>
	</div>
<!-- FOOTER -->
</body>
</html>